package com.zhentao.controller;

import com.zhentao.model.entity.system.SysMenu;
import com.zhentao.model.vo.common.Result;
import com.zhentao.model.vo.common.ResultCodeEnum;
import com.zhentao.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



@RestController
@RequestMapping(value = "/system/sysMenu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    //TODO 使用递归查询所有菜单
    @GetMapping(value = "/findNodes")
    public Result<List<SysMenu>> findNodes(){
        List<SysMenu> list = sysMenuService.findNodes();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    //TODO 添加菜单
    @PostMapping(value = "/saveMenu")
    public Result saveMenu(@RequestBody SysMenu sysMenu) {
        sysMenuService.saveMenu(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //TODO 修改菜单
    @PutMapping(value = "/updateMenuById")
    public Result updateMenuById(@RequestBody SysMenu sysMenu){
        sysMenuService.updateMenuById(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //TODO 删除菜单
    @DeleteMapping(value = "/removeMenuById/{Id}")
    public Result removeMenuById(@PathVariable(value = "Id") Integer id){
        sysMenuService.removeMenuById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

}
